package doc2db.table;


import java.util.ArrayList;
import java.util.List;

public class DocTableRows {
	private List<DocTableCell> rows = new ArrayList<DocTableCell>();

	public void add(String text, String h) {
		rows.add(new DocTableCell(text, h));
	}

	public void add(String text, String h, int len) {
		rows.add(new DocTableCell(text, h, len));
	}

	public void add(DocTableCell c) {
		rows.add(c);
	}

    public String get(int k){
        return rows.get(k).getName();
    }

    public DocTableCell getCell(int k){
        return rows.get(k);
    }

    public void set(int k, String s){
        rows.get(k).setName("" + s) ;
    }

    public String getCellHead(int k){
        return rows.get(k).getHead();
    }

    public void setCellHead(int k, String s){
        rows.get(k).setHead(s);
    }

	public String getInsertSQLString() {
		StringBuffer a = new StringBuffer();
		for (DocTableCell cell : rows) {
            a.append("\'");
            a.append(cell.getName());
            a.append("\'");
            a.append(",");
            a.append(" ");
        }
        a.deleteCharAt(a.length() - 1);
        a.deleteCharAt(a.length() - 1);
        return a.toString();
	}

	public String getWhereInsertSQLString() {
		StringBuffer a = new StringBuffer();
		for (DocTableCell cell : rows) {
            a.append("\"");
            a.append(cell.getHead());
            a.append("\"");
            a.append(",");
            a.append(" ");
        }
        a.deleteCharAt(a.length() - 1);
        a.deleteCharAt(a.length() - 1);
        return a.toString();
	}

	public int size() {
		return rows.size();
	}

    @Override
    public String toString() {
        StringBuffer ret = new StringBuffer("\n");
        int i = 0;
        for (DocTableCell c : rows) 
            ret.append("    [" + (i++) + "]" + c.toString() + "\n");
        return ret.toString();
    }
	
}
